<template>
  <div class="order-container">
    <div class="order-header">
      <div class="tab-group">
        <div 
          v-for="tab in tabs" 
          :key="tab.value"
          :class="['tab-item', { active: currentTab === tab.value }]"
          @click="currentTab = tab.value"
        >
          {{ tab.label }}
          <span class="badge" v-if="tab.count">{{ tab.count }}</span>
        </div>
      </div>
      <div class="search-box">
        <input type="text" placeholder="搜索订单" v-model="searchText" />
        <i class="iconfont icon-search"></i>
      </div>
    </div>

    <div class="order-list">
      <div v-for="order in orders" :key="order.id" class="order-item">
        <div class="order-top">
          <div class="order-info">
            <span class="order-id">订单号：{{ order.id }}</span>
            <span class="order-date">{{ order.date }}</span>
          </div>
          <div class="order-status" :class="order.status">{{ order.statusText }}</div>
        </div>

        <div class="product-info">
          <img :src="order.product.image" :alt="order.product.name" class="product-image" />
          <div class="product-details">
            <h3 class="product-name">{{ order.product.name }}</h3>
            <p class="product-desc">{{ order.product.description }}</p>
          </div>
          <div class="price-info">
            <div class="price">¥{{ order.product.price }}</div>
          </div>
        </div>

        <div class="seller-info">
          <img :src="order.seller.avatar" :alt="order.seller.name" class="seller-avatar" />
          <div class="seller-details">
            <span class="seller-name">{{ order.seller.name }}</span>
            <span class="seller-school">{{ order.seller.school }}</span>
          </div>
          <div class="trade-location">
            <i class="iconfont icon-location"></i>
            <span>{{ order.tradeLocation }}</span>
          </div>
        </div>

        <div class="order-actions">
          <button 
            v-for="action in order.actions" 
            :key="action.type"
            :class="['action-btn', action.type]"
          >
            {{ action.label }}
          </button>
        </div>
      </div>
    </div>

    <div class="empty-state" v-if="orders.length === 0">
      <i class="iconfont icon-empty"></i>
      <p>暂无相关订单</p>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const currentTab = ref('all');
const searchText = ref('');

const tabs = [
  { label: '全部订单', value: 'all', count: 8 },
  { label: '待付款', value: 'unpaid', count: 1 },
  { label: '待交易', value: 'pending', count: 2 },
  { label: '已完成', value: 'completed', count: 4 },
  { label: '已取消', value: 'cancelled', count: 1 }
];

const orders = ref([
  {
    id: '202402051234',
    date: '2024-02-05 14:30',
    status: 'pending',
    statusText: '待交易',
    product: {
      name: '二手笔记本电脑',
      description: '9成新 联想小新Air14 轻薄本',
      price: '2399',
      image: '/src/assets/products/laptop.jpg'
    },
    seller: {
      name: '李同学',
      school: '厦门大学',
      avatar: '/src/assets/default-avatar.jpg'
    },
    tradeLocation: '厦门大学图书馆一楼',
    actions: [
      { type: 'primary', label: '确认交易' },
      { type: 'default', label: '联系卖家' }
    ]
  },
  // 可以添加更多订单数据
]);
</script>

<style scoped>
.order-container {
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
}

.order-header {
  background: white;
  padding: 16px 24px;
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.tab-group {
  display: flex;
  gap: 32px;
}

.tab-item {
  position: relative;
  padding: 8px 0;
  color: #666;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab-item.active {
  color: #8b7355;
  font-weight: 500;
}

.tab-item.active::after {
  content: '';
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 100%;
  height: 2px;
  background: #8b7355;
}

.badge {
  background: #f0f0f0;
  color: #666;
  padding: 2px 6px;
  border-radius: 10px;
  font-size: 12px;
  margin-left: 4px;
}

.search-box {
  position: relative;
  width: 300px;
}

.search-box input {
  width: 100%;
  padding: 8px 16px;
  padding-right: 40px;
  border: 1px solid #e0d5c1;
  border-radius: 8px;
  outline: none;
}

.search-box i {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.order-item {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.order-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.order-info {
  display: flex;
  gap: 16px;
  color: #666;
}

.order-status {
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 14px;
}

.order-status.pending {
  background: #fff7e6;
  color: #fa8c16;
}

.order-status.completed {
  background: #f6ffed;
  color: #52c41a;
}

.order-status.cancelled {
  background: #f5f5f5;
  color: #999;
}

.product-info {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}

.product-image {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
}

.product-details {
  flex: 1;
}

.product-name {
  font-size: 16px;
  color: #333;
  margin-bottom: 8px;
}

.product-desc {
  color: #666;
  font-size: 14px;
}

.price-info {
  text-align: right;
}

.price {
  color: #f56c6c;
  font-size: 20px;
  font-weight: bold;
}

.seller-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  background: #f8f8f8;
  border-radius: 8px;
}

.seller-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.seller-details {
  display: flex;
  flex-direction: column;
}

.seller-name {
  color: #333;
  font-size: 14px;
}

.seller-school {
  color: #999;
  font-size: 12px;
}

.trade-location {
  margin-left: auto;
  color: #666;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.order-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.action-btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
}

.action-btn.primary {
  background: #8b7355;
  color: white;
}

.action-btn.default {
  background: #f5f5f5;
  color: #666;
}

.empty-state {
  text-align: center;
  padding: 48px;
  color: #999;
}

.empty-state i {
  font-size: 48px;
  margin-bottom: 16px;
}
</style>